#include<bits/stdc++.h>
using namespace std;
struct stu
{
	string a;
	int yu,shu,ying,sum;
	bool operator < (const stu & x) const
	{
		return x.a>a;
	}
}s[1001];
//bool cmp(stu x,stu y)
//{
//	return x.a<y.a;
//}
int main()
{
	int j,n,i;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>s[i].a>>s[i].yu>>s[i].shu>>s[i].ying;
		s[i].sum=s[i].yu+s[i].shu+s[i].ying;
	}
	sort(s+1,s+i);
	for(i=1;i<n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(abs(s[i].yu-s[j].yu)<=5&&abs(s[i].shu-s[j].shu)<=5&&abs(s[i].ying-s[j].ying)<=5&&abs(s[i].sum-s[j].sum)<=10)
			cout<<s[i].a<<" "<<s[j].a<<endl;
		}
	}
    return 0;
}
